﻿/*
 * @Author: Song Xinxin
 * @Date: 2022-11-07 16:33:27
 * @LastEditors: Song Xinxin
 * @LastEditTime: 2022-11-08 10:54:43
 * @FilePath: \WYW_0419_Oasis\JavaScripts\Modules\Dress\Module_Dress.ts
 * @Description: 
 * 
 * Copyright (c) 2022 by error: git config user.name && git config user.email & please set dead value or install git, All Rights Reserved. 
 */
import { ModuleC, ModuleS } from "odin";

export class ModuleS_Dress extends ModuleS<ModuleC_Dress,null>
{
    /**
     * 让指定客户端看见自己的服装
     * @param player 指定客户端玩家
     * @param guid 要换的服装
     */
	public sendDress(player:GamePlay.Player,guid:string[]):void
	{
		this.callClientFun(player,this.client.net_changeDress(this.currentPlayer,guid));
	}

	/**
	 * 让当前所有客户端看见自己的服装
	 * @param guid 要换的服装
	 */
	public sendDressAll(guid:string[]):void
	{
		this.callWorldClientFun(this.client.net_changeDress(this.currentPlayer,guid));
	}

    /**
     * 让当前玩家看见NPC服装
     * @param NPC 
     * @param guid 
     */
    public sendNPC_Dress(NPC:GamePlay.Humanoid,guid:string[]):void
    {   
        this.callClientFun(this.currentPlayer,this.client.net_changeDress(NPC,guid));
    }


}

export class ModuleC_Dress extends ModuleC<ModuleS_Dress,null>
{
    
    /**
     * 换装
     * @param chara 玩家或人形对象
     * @param guid 服装guid数组
     */
    public net_changeDress(chara:GamePlay.Humanoid|GamePlay.Player,guid:string[]):void
    {
        this.loadDressData(chara,guid);
    }

    /**
     * 加载服装
     * @param chara 玩家或人形对象
     * @param guid 服装guid数组
     */
    public loadDressData(chara:GamePlay.Humanoid|GamePlay.Player,guid:string[],len?:number):void
    {
        //NPC
        if(chara instanceof GamePlay.Humanoid)
        {

            if(len == null)
            {
                len = guid.length - 1;
                this.loadDressData(chara,guid,len);
            }
            else if(len > -1)
            {
                chara.loadEditorDataByGuid(guid[len],this.loadDressData(chara,guid,len - 1));
            }
            else
            { 
                chara.loadEditorDataAllCompletedDelegate.add(()=>
                {
                    chara.syncDIYDataBegin(); 
                });
            }

        }
        else//玩家
        {
            if(len == null)
            {
                len = guid.length - 1;
                this.loadDressData(chara,guid,len);
            }
            else if(len > -1)
            {
                chara.character.loadEditorDataByGuid(guid[len],this.loadDressData(chara,guid,len - 1));
            }
            else
            {
                chara.character.loadEditorDataAllCompletedDelegate.add(()=>
                {
                   chara.character.syncDIYDataBegin(); 
                });
            }
        }
    }
    
}